#pragma once

class Session
{
public:
    Session(const std::string& user):_user(user)
    {

    }
    std::string User()
    {
        return _user;
    }
private:
    std::string _user;
};
using session_ptr = std::shared_ptr<Session>;

class SessionManager
{
public:
    SessionManager()
    {
        srand(time(nullptr));
    }
    //说明
    std::string AddSession(session_ptr s)
    {
        unsigned int randomid = rand()+time(nullptr);
        std::string sessionid = std::to_string(randomid);
        _sessions[sessionid] = s;
       //_sessions.insert(make_pair(sessionid,s));
       return sessionid;
    }
    session_ptr GetSession(const std::string& sessionid)
    {
        if(_sessions.find(sessionid) == _sessions.end()) return nullptr;
        return _sessions[sessionid];
    }
    void Print()
    {
        std::cout<<"sessions:";
        for(auto& e:_sessions)
        {
            std::cout<<e.first<<":"<<e.second<<std::endl;
        }
    }
private:
    std::unordered_map<std::string,session_ptr> _sessions;
};